const { Service } = require("egg");

class TopicMaterialService extends Service {
    async list(topicId) {
        return await this.app.model.TopicMaterial.findAll(
            {
                where: {
                    topicId
                },
                order: [['updatedAt', 'DESC']],
                raw: true,
            }
        );
    }
    async create(data) {
        return await this.app.model.TopicMaterial.create(data);
    }

    async delete(id) {
        return await this.app.model.TopicMaterial.destroy({
            where: { id },
        });
    }

    async update(id, updateData) {
        const updated = await this.app.model.TopicMaterial.update(updateData, {
            where: { id },
        });
        return updated[0] ? updated[0] : null;

    }
}

module.exports = TopicMaterialService;
